<template>
    <el-card>
        <div slot="header">
            <span>{{ popData.title }}</span>
        </div>
        <el-form :model="form">
            <el-row :gutter="20">
                <% columnList.forEach(function (item) { %>
                    <el-col :span="12">
                        <el-form-item prop="<%= item.field %>" label="<%= item.comment %>">
                            <el-input v-model="form.<%= item.field %>" aria-placeholder="请输入<%= item.comment %>"/>
                        </el-form-item>
                    </el-col>
                <% }) %>
            </el-row>
            <el-row v-if="popData.type !== 2">
                <el-col :span="4">
                    <el-button @click="edit">保存</el-button>
                </el-col>
                <el-col :span="4">
                    <el-button @click="cancel">取消</el-button>
                </el-col>
            </el-row>
        </el-form>
    </el-card>
</template>
<script>
    import {edit<%= table.className %>, get<%= table.className %>ById } from '@/api/<%= table.firstLowerClassName %>'

    export default {
        name: '<%= table.className %>Form',
        props: ['popData'],
        data() {
            return {
                form: {}
            }
        },
        created() {
            this.detail()
        },
        methods: {
            detail(){
              const id = this.popData.id
              if(id) {
                  get<%= table.className %>ById(id).then(resp => {
                      this.form = resp.data
                  })
              }
            },
            edit() {
                edit<%= table.className %>(this.form).then(resp => {
                    this.$message.success(resp.message)
                    this.$parent.closePop()
                })
            },
            cancel() {
                this.$parent.closePop()
            }
        }
    }
</script>
